#include "ContainerPainter.h"
#include "Container.h"
#include "Control.h"
#include "../Util/Util.h"
#include "../debug_new.h"

CContainerPainter::CContainerPainter()
{

}

void CContainerPainter::Paint(CDC* pDc, CContainer* pContainer, CRect& rc)
{
	PaintBkgnd(pDc,pContainer,rc);
	PaintControls(pDc,pContainer,rc);
}

void CContainerPainter:: PaintBkgnd(CDC* pDc, CContainer* pContainer, CRect& rc)
{
	if(pContainer->GetBackGnd())
	{
		CDC dcTmp;
		dcTmp.CreateCompatibleDC(NULL);
		HBITMAP hBmpOld = dcTmp.SelectBitmap(pContainer->GetBackGnd());
		//pDc->BitBlt(0,0,CUtil::GetScreenWidth(),CUtil::GetScreenHeight(),dcTmp.m_hDC,0,0,SRCCOPY);
		pDc->BitBlt(0,0,pContainer->GetRect().Width(),pContainer->GetRect().Height(),dcTmp.m_hDC,0,0,SRCCOPY);
		dcTmp.SelectBitmap( hBmpOld );
		dcTmp.DeleteDC();
	}
	else
	{
		pDc->FillSolidRect(rc,pContainer->GetBackColor());
	}
}

void CContainerPainter:: PaintControls(CDC* pDc, CContainer* pContainer, CRect& rc)
{
	int nCount = pContainer->m_vecControls.size();

	for(int i=0; i < nCount; i++)
		pContainer->m_vecControls.at(i)->Paint(pDc);
}
